﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using CommunitySystem.Model;
using CommunitySystem.BO;
using System.Collections.ObjectModel;
using CommunitySystemModel;
using CommunitySystem.BO.SystemManager;
namespace CommunitySystem.Web.Service
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "DataService" in code, svc and config file together.
    public class DataService : IDataService
    {
        #region 数据字典
        DictionaryBo bo = new DictionaryBo("DD");
        public IList<DictionaryModel> GetDictionaryModels(string parentId)
        {
            return bo.GetSpouseByPID(parentId);
        }

        public IList<DictionaryModel> GetDictionaryModels1(string parentId)
        {
            return bo.GetSpouseByPID(parentId);
        }

        public IList<DictionaryModel> GetDictionarys()
        {

            return bo.GetDictionarys();
        }

        public DictionaryModel GetDictionaryByCode(string dictCode)
        {
            //var model = DataAccessor.QueryForObject<DictionaryModel>("SelectDictionaryByCode", dictCode);
            return null;
        }

        public int InsertDictionary(List<DictionaryModel> model)
        {
            //if (model.Count > 0)
            //{
            //    model.ToList().ForEach(t => DataAccessor.Insert("InsertDictionary", t));
            //    return 1;
            //}
            //else
                return 0;
        }

        /// <summary>
        /// 获取数据字典 written by tollin
        /// </summary>
        /// <param name="DictCode"></param>
        /// <returns></returns>
        public DataDictionaryModel GetDictModel(string DictCode, string parameter)
        {
            return bo.GetDataDictionaryModel(DictCode, parameter);
        }
        #endregion

        #region 菜单管理
        MenuManagerBO bo2 = MenuManagerBO.GetInstance();
        public ObservableCollection<MenuItem> GetMenuByContidtion(string condition)
        {
            return bo2.GetMenuItem(condition);
        }

        ObservableCollection<MenuItem> IDataService.GetMenuByPID(int pid)
        {
            return bo2.GetMenuItemByPID(pid);
        }


        public void AddMenuItem(MenuItem item)
        {
            bo2.AddMenuItem(item);
        }

        public void UpdateMenuItem(MenuItem item)
        {
            bo2.UpdateMenuItem(item);
        }

        public void DeleteMenuItem(int id)
        {
            bo2.DeleteMenuItem(id);
        }

        public MenuItem ValidateIsDefault(MenuItem mi)
        {
            return bo2.GetMenuItem("pid =0 and IsDefault=1 and id<>" + mi.ID).FirstOrDefault();
        }

        

        public ObservableCollection<MenuItem> GetSubMenuByUserID(int userid, int topid)
        {
            return bo2.GetSubMenuByUserID(userid, topid);
        }
        #endregion






        public DataDictionaryModel GetDictModel(string DictCode)
        {
            throw new NotImplementedException();
        }

        public ObservableCollection<MenuItem> GetMenuByContidtion(string condition, string parameter)
        {
            throw new NotImplementedException();
        }


        
    }
}
